package setting

import (
	"io/ioutil"

	log "github.com/sirupsen/logrus"

	yaml "gopkg.in/yaml.v2"
)

type config struct {
	RunMode           string     `yaml:"RunMode"`
	AppSetting        app        `yaml:"APP"`
	HTTPSetting       http       `yaml:"HTTP"`
	FileServerSetting fileServer `yaml:"FileServer"`
}

type app struct {
	RuntimePath string `yaml:"RuntimePath"`
	LogFilePath string `yaml:"LogFilePath"`

	BaiduAIAppKey    string `yaml:"BaiduAIAppKey"`
	BaiduAISecretKey string `yaml:"BaiduAISecretKey"`
}
type http struct {
	Port         int `yaml:"Port"`
	ReadTimeout  int `yaml:"ReadTimeout"`
	WriteTimeout int `yaml:"WriteTimeout"`
}

type fileServer struct {
	StoragePath              string   `yaml:"StoragePath"`
	ThumbnailImageFolderName string   `yaml:"ThumbnailImageFolderName"`
	OriginImageFolderName    string   `yaml:"OriginImageFolderName"`
	ImageMaxSize             int      `yaml:"ImageMaxSize"`
	ImageAllowExts           []string `yaml:"ImageAllowExts"`
}

var Cfg = config{}

func Setup() {

	yamlFile, err := ioutil.ReadFile("conf/config.yml")
	if err != nil {
		log.Panicf("yamlFile.Get err #%v ", err)
	}
	err = yaml.Unmarshal(yamlFile, &Cfg)
	// err = yaml.Unmarshal(yamlFile, &resultMap)
	if err != nil {
		log.Panicf("Unmarshal: %v", err)
	}
}
